home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1985 June
/
Ahoy_Magazine_85-06_1985_Double_L.d64
/
6510 simulator
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
11KB
|
322 lines
100 rem ******* 6510 simulator ********
110 data asl,brk,clc,cld,cli,clv,dex,dey,inx,iny,lsr,nop,pha,php,pla
120 data plp,rol,ror,rti,rts,sec,sed,sei,tax,tay,tsx,txa,txs,tya
130 data adc,and,cmp,cpx,cpy,eor,lda,ldx,ldy,ora,sbc
140 data adc,and,asl,bcc,bcs,beq,bit,bmi,bne,bpl,bvc,bvs,cmp,cpx,cpy
150 data dec,eor,inc,jmp,jsr,lda,ldx,ldy,lsr,ora,rol,ror,sbc,sta,stx
160 data sty,asl,lsr,rol,ror
170 data 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
180 data 0000,0001,0010,0011,0100,0101,0110,0111
190 data 1000,1001,1010,1011,1100,1101,1110,1111
200 dim hex$(8),bit$(8),h$(16),b$(16),temp$(2),bit(8),n$(75)
210 ah$="00":xh$="00":yh$="00":z$="0":ad=0:sc=0:yd=0
220 ab$="00000000":xb$="00000000":yb$="00000000"
230 n=0:v=0:b=0:d=0:i=0:z=0:c=0
240 if right$(a$,1)=" "then 300:rem type a space between the quotes
250 for l=1 to 75:read n$(l):next l
260 for l=1 to 16:read h$(l):next l:for l=1 to 16:read b$(l):next l
270 print "[147]":poke53280,0:poke53281,6:poke646,1
280 print " n v - b d i z c"
285 print n;v;" - ";b;d;i;z;c:print
290 print "a: ";ah$;" x: ";xh$;" y: ";yh$
295 print ab$;" ";xb$;" ";yb$:print
300 b=0:a$="":input " ";a$:rem type space between second pair of quotes
320 if len(a$)<3 or len(a$)>10 then 300
330 if len(a$)=3 then 420:rem go to implied-address routines
340 if mid$(a$,4,1)<>chr$(32) then 300
350 if right$(a$,1)=chr$(32) then 300
360 goto 450:rem go to immediate- and absolute-address routines
370 rem *** routine to convert op$ & ad$ to binary numbers ***
380 od$=op$:gosub 1130:for l=1 to 8:bit$(l)=z$:next l
390 for l=1 to 8:b1$(l)=mid$(ob$,l,1):next l
400 for l=1 to 8:b2$(l)=mid$(ab$,l,1):next l:return
410 rem *** implied-addressing routines ***
420 for l=1 to 29:if a$=n$(l) then oc$=a$:oc=l:goto 1350
430 next l:goto 300
440 rem *** immediate, absolute & accumulator address modes ***
450 oc$=left$(a$,3):op$=mid$(a$,5)
460 if left$(op$,1)="#" and mid$(op$,2,1)="$" then flag$="ah":goto 530
470 if left$(op$,1)="#" then flag$="ad":goto 620
480 if left$(op$,1)="$" then flag$="ih":goto 690
490 if op$="a" then 790
500 if left$(op$,1)<"0" and left$(op$,1)>"9" then 300:rem try again
510 flag$="id":goto 840
520 rem *** hex operand, absolute address ***
530 op$=mid$(op$,3)
540 for l=30 to 40:if oc$=n$(l) then oc=l:goto 560
550 next l:goto 300
560 if len(op$)>2 then 300
570 for l=1 to len(op$):x$=mid$(op$,l,1):if x$<z$ or x$>"f" then 300
580 if x$>"9"and x$<"a" then 300
590 if len(op$)=1 then op$=z$+op$
600 oh$=op$:gosub 1030:op$=od$:goto 670
610 rem *** decimal operand, absolute addressing ***
620 op$=mid$(op$,2)
630 for l=30to 40:if oc$=n$(l) then oc=l:goto 650
640 next l:goto 300
650 if val(op$)>255 then 300
660 for l=1 to len(op$):x$=mid$(op$,l,1):ifasc(x$)<48 or asc(x$)>57 then 420
670 oc=oc-29:goto 1420
680 rem *** hex operand, immediate address ***
690 op$=mid$(op$,2)
700 for l=41 to 71:if oc$=n$(l) then oc=l:goto720
710 next l:goto 300
720 if len(op$)>4 then 300
730 for l=1 to len(op$):x$=mid$(op$,l,1):if x$<z$ or x$>"f" then 300
740 if x$>"9" and x$<"a" then 300
750 next l
760 oh$=op$:gosub 1030:op$=od$:op$=str$(peek(val(op$)))
770 oc=oc-40:goto 1430
780 rem *** accumulator addressing ***
790 op$="a"
800 for l=72 to75:if oc$=n$(l) then oc=l-71: goto 820
810 next l:goto 300
820 on oc goto 1510,1760,1790,1810
830 rem *** decimal operand, immediate address **
840 if val(op$)>65535 then 300
860 for l=1 to len(op$):x$=mid$(op$,l,1):if asc(x$)<48 or asc(x$)>57 then 300
870 for l=41 to 71:if oc$=n$(l) then oc=l:goto 890
880 next l:goto 300
890 op$=str$(peek(val(op$)))
900 oc=oc-40:goto 1430
910 rem *** decimal-to-hexadecimal conversion ***
920 for l=1 to 4:hex$(l)="":next l
930 for l=1 to 5:t$=right$(od$,l):next l
940 nr=val(od$):x=4
950 tmp=nr:nr=int(nr/16):tmp=tmp-nr*16
960 if tmp<10 then hex$(x)=right$(str$(tmp),1):goto 980
970 hex$(x)=chr$(tmp-10+asc("a"))
980 if nr<>0 then x=x-1:goto 950
990 oh$=hex$(1)+hex$(2)+hex$(3)+hex$(4)
1000 if len(oh$)=1 then oh$=z$+oh$
1010 return
1020 rem *** hexadecimal-to-decimal conversion ***
1030 nr=0:for l=1 to len(oh$):hex$(l)=mid$(oh$,l,1)
1040 if hex$(l)<="9" then nr=nr*16+val(hex$(l)):goto 1060
1050 nr=nr*16+asc(hex$(l))-asc("a")+10
1060 next l:od$=str$(nr):return
1070 rem *** binary-to-decimal conversion ***
1080 for l=8 to 1 step -1:b$(l)=mid$(ob$,l,1):next l
1090 for l=1 to 8:bit(l)=val(b$(l)):next l:od=0:nr=256
1100 for l=1 to8:nr=nr/2:od=od+bit(l)*nr:next l
1110 od$=str$(od):return
1120 rem *** decimal-to-binary conversion ***
1130 od=val(op$):for l=8 to 1 step -1:tmp=od/2:nr=tmp-int(tmp)
1140 if nr=0 then bt$(l)=z$:goto 1160
1150 bt$(l)="1"
1160 od=int(tmp):next l
1170 ob$=bt$(1)+bt$(2)+bt$(3)+bt$(4)+bt$(5)+bt$(6)+bt$(7)+bt$(8):return
1180 rem *** hex-to-binary conversion ***
1190 hex$(1)="":hex$(2)="":for l=1 tolen (oh$):hex$(l)=mid$(oh$,l,1)
1200 next l:if hex$(2)="" then hex$(2)=hex$(1):hex$(1)=z$
1210 for l=1 to 16:if hex$(1)=h$(l) then bit$(1)=b$(l)
1220 next l:for l=1 to 16:if hex$(2)=h$(l) then bit$(2)=b$(l)
1240 next l:ob$=bit$(1)+bit$(2):print:return
1260 rem *** binary-to-hex conversion ***
1270 for l=1 to 8:bit$(l)=mid$(ob$,l,1):next l
1280 bit$=bit$(1)+bit$(2)+bit$(3)+bit$(4)+bit$(5)+bit$(6)+bit$(7)+bit$(8)
1290 t1$=left$(bit$,4):t2$=right$(bit$,4):for l=1 to 16
1300 if t1$=b$(l)then hex$(1)=h$(l)
1310 next l:for l=1 to 16:if t2$=b$(l) then hex$(2)=h$(l)
1320 next l:if hex$(1)="" then hex$(1)=z$
1330 oh$=hex$(1)+hex$(2):return
1340 rem *** on/goto data ***
1350 on oc goto 1510,1560,1570,1580,1590,1600,1610,1650,1690,1730
1360 nr=oc-10:on nr goto 1760,1780,1780,1780,1780,1780,1790,1810,1830,1840
1380 nr=nr-10:on nr goto 1850,1860,1870,1880,1900,1920,1930,1940,1950,1840
1400 nr=nr-10:on nr goto 1850,1860,1870,1880,1900,1920,1930,1940,1950,1950
1420 on oc goto 1970,2100,2170,2250,2320,2390,2450,2550,2650,2750,2810
1430 on oc goto 1970,2350,3250,1780,1780,1780,3200,1780,1780,1780
1440 nr=oc-10:on nr goto 1780,1780,3250,2250,2320,3260,2390,3290,1780,1780
1460 nr=nr-10:on nr goto 2450,2550,2650,3320,2750,3340,3360,2810,1780,1780
1480 nr=nr-10:on nr goto 1780,3390
1500 rem *** implied-address op-code routines
1510 c=val(left$(ab$,1)):ab$=mid$(ab$,2)+z$:rem *** asl ***
1520 ob$=ab$:gosub 1270:ah$=oh$:op$=oh$:gosub 1030:n=0:z=0
1530 if left$(ob$,1)="1"then n=1
1540 if val(od$)=0then z=1
1550 goto 3390
1560 b=1:goto 3390:rem *** brk ***
1570 c=0:goto 3390:rem *** clc ***
1580 d=0:goto 3390:rem *** cld ***
1590 i=0:goto 3390:rem *** cli ***
1600 v=0:goto 3390:rem *** clv ***
1610 oh$=xh$:gosub 1030:xd=val(od$):rem *** dex **
1620 xd=xd-1:if xd<0 then xd=255
1630 od$=str$(xd):gosub920:xh$=oh$:gosub 1190:xb$=ob$
1640 tmp=xd:gosub 3410:goto 280
1650 oh$=yh$:gosub 1030:yd=val(od$):rem *** dey ***
1660 yd=yd-1:if yd<0 then yd=255
1670 od$=str$(yd):gosub 920:yh$=oh$:gosub 1190:yb$=ob$
1680 tmp=yd:gosub 3410:goto 280
1690 oh$=xh$:gosub 1030:xd=val(od$):rem *** inx ***
1700 od$=str$(xd):gosub 920:xh$=oh$:gosub 1190:xb$=ob$
1710 xd=xd+1:if xd>255 then xd=0
1720 goto 1630
1730 oh$=yh$:gosub 1030:yd=val(od$):rem *** iny ***
1740 yd=yd+1:if yd>255 then yd=0
1750 goto 1670
1760 c=val(right$(ab$,1)):ab$=z$+left$(ab$,7):rem *** lsr ***
1770 goto 1520
1780 goto 3390:rem *** nop,pha,php,pla and plp ***
1790 goto 3340:rem *** rol ***
1810 goto 3360:rem *** ror ***
1830 n=0:v=0:b=0:d=0:i=0:z=0:c=0:goto 280 rem *** rti ***
1840 (NULL)t 3390:rem *** rts ***
1850 c=1:goto 3390:rem *** sec ***
1860 d=1:goto 3390;rem *** sed ***
1870 i=1:goto 3390:rem *** sei ***
1880 xh$=ah$:xb$=ab$:op$=ah$:gosub 1030:tmp=val(od$):rem *** tax ***
1890 gosub 3410:goto 3390
1900 yh$=ah$:yb$=ab$:op$=ah$:gosub 1030:tmp=val(od$):rem *** tay ***
1910 gosub 3410:goto 3390
1920 xh$="00":xb$="00000000":gosub 3410:goto 3390:rem *** tsx ***
1930 ah$=xh$:ab$=xb$:goto 1520:rem *** txa ***
1940 goto 3390:rem *** txs ***
1950 ah$=yh$:ab$=yb$:goto 1520:rem *** tya ***
1960 rem *** absolute-address operands ***
1970 if d then 2950:rem *** adc ***
1980 op=val(op$):tmp$=ab$
1990 gosub 1130:plus$=ob$
2000 oh$=ah$:gosub 1030:ad$=od$:ad=val(ad$):tmp=ad
2010 ad=ad+op+c:c=0:if ad>255 then gosub 2090
2020 ad$=str$(ad):od$=ad$:gosub920:ah$=oh$
2030 gosub 1190:ab$=ob$
2040 n=0:if ad>127 then n=1
2050 z=0:if ad=0 then z=1
2060 v=0
2070 if left$(tmp$,1)=left$(plus$,1) and left$(tmp$,1)<>left$(ab$,1)then v=1
2080 od$=ad$:gosub 1030:ah$=oh$:goto 280
2090 c=1:ad=ad-256:return
2100 gosub 380:rem *** and ***
2110 for l=1 to 8:bit$(l)="0":next l
2120 for l=1 to 8:if b1$(l)="1" and b2$(l)="1" then bit$(l)="1"
2130 next l
2140 ab$=bit$(1)+bit$(2)+bit$(3)+bit$(4)+bit$(5)+bit$(6)+bit$(7)+bit$(8)
2150 ob$=ab$:gosub 1270:ah$=oh$
2160 gosub 1030:tmp=val(od$):gosub3410:print:goto 280
2170 oh$=ah$:gosub 1030:ad$=od$:ad=val(ad$):op=val(op$):rem *** cmp ***
2180 z=0:if ad=op then z=1
2190 n=0:if op>ad then n=1
2220 c=0:if ad>op or ad=op then c=1
2240 goto 3390
2250 oh$=xh$:gosub 1030:xd$=od$:xd=val(xd$):op=val(op$):rem *** cpx ***
2260 z=0:if xd=op then z=1
2280 n=0:if op>xd then n=1
2300 c=0:if xd>op or xd=op then c=1
2310 goto 3380
2320 oh$=yh$:gosub 1030:yd$=od$:yd=val(yd$):op=val(op$):rem *** cpy ***
2330 z=0:if yd=op then z=1
2340 n=0:if op>yd then n=1
2350 c=0:if yd>op or yd=op then c=1
2380 goto 3380
2390 gosub 380:rem *** eor ***
2400 for l=1 to 8:bit$(l)=z$:next l
2410 for l=1 to 8:if b1$(l)="1" and b2$(l)="1" then bit$(l)="0":goto 2440
2420 if b1$(l)="1" or b2$(l)="1" then bit$(l)="1"
2440 next l:goto 2140
2450 if d=1 then 2480:rem *** lda ***
2460 od$=op$:gosub 920:ah$=oh$:gosub 1190:ab$=ob$
2470 tmp=val(op$):gosub 3410:goto 280
2480 if flag$="ad" and val(op$)>99 then 300
2490 if flag$<>"ad" then od$=op$:gosub 920:ah$=oh$:goto 2530
2500 if len(op$)=1 then op$=z$+op$
2510 ah$=op$:oh$=ah$:goto 2530
2520 od$=op$:gosub 920:ah$=oh$
2530 gosub 1190:ab$=ob$
2540 tmp=val(op$):gosub 3410:goto 2470
2550 if d=1 then 2580:rem *** ldx ***
2560 od$=op$:gosub 920:xh$=oh$:gosub 1190:xb$=ob$
2570 tmp=val(op$):gosub 3410:goto 280
2580 if flag$="ad" and val(op$)>99 then 300
2590 if flag$<>"ad" then od$=op$:gosub 920:xh$=oh$:goto 2630
2600 if len(op$)=1 then op$=z$+op$
2610 xh$=op$:oh$=xh$:goto 2630
2620 od$=op$:gosub 920:xh$=oh$
2630 gosub 1190:xb$=ob$
2640 tmp=val(op$):gosub 3410:goto 2570
2650 if d=1 then 2680:rem *** ldx ***
2660 od$=op$:gosub 920:yh$=oh$:gosub 1190:yb$=ob$
2670 tmp=val(op$):gosub 3410:goto 280
2680 if flag$="ad" and val(op$)>99 then 300
2690 if flag$<>"ad" then od$=op$:gosub 920:yh$=oh$:goto 2730
2700 if len(op$)=1 then op$=z$+op$
2710 yh$=op$:oh$=yh$:goto 2730
2720 od$=op$:gosub 920:xh$=oh$
2730 gosub 1190:yb$=ob$
2740 tmp=val(op$):gosub 3410:goto 2670
2750 gosub 380:rem *** ora ***
2760 for l=1 to8:if b1$(l)="1" or b2$(l)="1" then bit$(l)="1"
2770 next l:ab$="":for l=1 to 8:ab$=ab$+bit$(l):next l
2790 ob$=ab$:gosub 1270:ah$=oh$
2800 gosub 1030:tmp=val(od$):gosub3410:goto 3390
2810 if d then 3060:rem *** sbc ***
2820 op=val(op$):tmp$=ab$
2830 gosub 1130:mi$=ob$
2840 oh$=ah$:gosub 1030:ad$=od$:ad=val(ad$):tmp=ad
2850 ad=ad-op:if c=0 then ad=ad-1
2860 if ad<0 then ad=256+ad:c=0
2870 ad$=str$(ad):od$=ad$:gosub 920:ah$=oh$
2880 gosub 1190:ab$=ob$
2890 n=0:if ad>127 then n=1
2900 z=0:if ad=0 then z=1
2910 v=0:if left$(tmp$,1)=left$(mi$,1) then 2930
2920 if left$(ab$,1)=left$(tmp$,1) then v=1
2930 od$=ad$:gosub 1030:ah$=oh$:goto 280
2940 rem *** bcd addition routine ***
2950 if flag$<>"ad" then 1980
2960 if left$(ah$,1)>"9" or right$(ah$,1)>"9" then 3030
2970 ad=val(ah$)
2980 op=val(op$):ad=ad+op+c:c=0
2990 gosub 1030:tmp=val(od$):gosub 3410
3000 if ad>99 then gosub 3040
3010 ah$=str$(ad):if len(ah$)=1 then ah$=z$+ah$
3020 oh$=ah$:gosub 1190:ab$=ob$:goto 280
3030 oh$=ah$:gosub 1030:ad$=od$:ad=val(ad$):goto 2980
3040 c=1:ad=ad-100:return
3050 rem *** bcd subtraction routine ***
3060 if flag$<>"ad" then 2820
3070 if left$(ah$,1)>"9" or right$(ah$,1)>"9" then 3120
3080 ad=val(ah$):op=val(op$):ad=ad-op:if c=0 then ad=ad-1
3100 if ad<0 then gosub 3130
3110 goto 3010
3120 oh$=ah$:gosub 1030:ad$=od$:ad=val(ad$):goto 3090
3130 c=0:ad=100+ad:return
3140 rem *** immediate-address routines ***
3150 od$=op$:gosub 920:gosub 1190:rem *** asl ***
3160 c=val(left$(ob$,1)):ob$=mid$(ob$,2)+z$
3170 gosub 1270:gosub 1030:x=val(od$):n=0:if x<0 then n=1
3180 z=0:if x=0 then z=1
3190 goto 280
3200 gosub 1030:ad=val(od$):rem *** bit ***
3210 gosub 1130:n=val(left$(ob$,1)):v=val(mid$(ob$,2,1))
3220 gosub 400:z=1:for l=1 to 8
3230 if b1$(l)="1" and b2$="1" then z=0
3240 next l:goto 3390
3250 goto 2170
3260 op=val(op$):op=op-1:if op<0 then n:rem *** dec ***
3270 if op=0 then z=1
3280 goto 3390
3290 op=val(op$):op=op+1:if op<0 then n=1:rem *** inc ***
3300 if op=z then z=1
3310 goto 3390
3320 od$=op$:gosub 920:gosub 1190
3330 c=val(right$(ob$,1)):ob$=z$+left$(ob$,7):goto 3170
3340 if c=1 then j$="1":rem *** rol ***
3341 if c=0 then j$="0"
3342 c=val(left$(ab$,1)):ab$=right$(ab$,7)+j$
3350 ob$=ab$:gosub 1270:ah$=oh$:op$=oh$:gosub 1030:n=0:z=0
3355 if left$(ob$,1)="1" then n=1
3356 if val(od$)=0then z=1
3357 goto 3390
3360 if c=1 then j$="1":rem *** ror ***
3365 if c=0 then j$=z$
3370 c=val(right$(ab$,1)):ab$=j$+left$(ab$,7)
3371 goto 3350
3380 rem *** print line space & get another line ***
3390 print:goto 280
3400 rem *** set z and n flags ***
3410 n=0:if tmp>127 then n=1
3420 z=0:if tmp=0 then z=1
3430 return